package com.gml.design.abstractFactory.optimize;

import com.gml.design.abstractFactory.optimize.factory.JDKProxyFactory;
import com.gml.design.abstractFactory.optimize.workshop.ICacheAdapter;
import com.gml.design.abstractFactory.optimize.workshop.impl.EGMCacheAdapter;
import com.gml.design.abstractFactory.optimize.workshop.impl.IIRCacheAdapter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

public class Test {
    private static Logger logger = LoggerFactory.getLogger(Test.class);

    /**
     * 使用动态代理，作为工厂，此工厂是抽象了redis集群使用类的工厂
     * 不同的redis集群，由各自的工厂实现存储逻辑，各自维护各自的使用逻辑
     * 给动态工厂传入想要使用的集群类型，该抽象工厂会实例化对应的工厂实现，然后返回对应的工厂
     * 最后由具体的实现逻辑的工厂进行存储逻辑
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        ICacheAdapter proxy_EGM = JDKProxyFactory.getProxy(ICacheAdapter.class, EGMCacheAdapter.class);
        proxy_EGM.set("user_name_01", "小傅哥");
        proxy_EGM.set("user_name_01", "小傅哥", 100, TimeUnit.DAYS);
        String val01 = proxy_EGM.get("user_name_01");
        logger.info("缓存服务 EGM 测试，proxy_EGM.get 测试结果：{}", val01);

        ICacheAdapter proxy_IIR = JDKProxyFactory.getProxy(ICacheAdapter.class, IIRCacheAdapter.class);
        proxy_IIR.set("user_name_01", "小傅哥");
        String val02 = proxy_IIR.get("user_name_01");
        logger.info("缓存服务 IIR 测试，proxy_IIR.get 测试结果：{}", val02);
    }
}
